//
//  YSClubDataTool.m
//  Yueshi
//
//  Created by yueshi_tech on 15/7/15.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSClubDataTool.h"

@implementation YSClubDataTool

+(void)getInterestGroup:(void (^)(YSInterestGroupRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@interest/interestGroups",BASE_URL] param:params hasT:NO resultClass:[YSInterestGroupRes class] success:success failure:failure];
}

+ (void)getClubInfo:(void (^)(YSHomeInfoRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@app/clubIndex",BASE_URL] param:params hasT:NO resultClass:[YSHomeInfoRes class] success:success failure:failure];
}

+(void)getProductDetail:(NSInteger)prodId isLogin:(BOOL)isLogin success:(void (^)(YSProductDetailRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
  
    [params setObject:[NSNumber numberWithInteger:prodId] forKey:@"prodId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/detail",BASE_URL] param:params hasT:isLogin resultClass:[YSProductDetailRes class] success:success failure:failure];
}

+(void)markProductWithProdId:(NSString *)prodId isMark:(NSInteger)isMark success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:prodId forKey:@"prodId"];
    [params setObject:[NSNumber numberWithInteger:isMark] forKey:@"isMark"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/mark",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)addCartWithParam:(NSInteger)prodId prodCount:(NSInteger)prodCount type:(NSInteger)type success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:prodId] forKey:@"prodId"];
    [params setObject:[NSNumber numberWithInteger:prodCount] forKey:@"prodCount"];
    if(type == 1){
        [params setObject:[NSNumber numberWithInteger:type] forKey:@"type"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@cart/add",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)deleteCartWithParam:(NSInteger)prodId success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:prodId] forKey:@"prodId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@cart/delete",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getCartInfo:(void (^)(YSCartRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@cart/buyCart",BASE_URL] param:params hasT:ISLOGIN resultClass:[YSCartRes class] success:success failure:failure];
}

+(void)expiredCart:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@cart/expired",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getAccountCenterWithOrderCode:(NSString *)orderCode prodIds:(NSString *)prodIds success:(void (^)(YSAccountCenterRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    if(!ISBLANK(orderCode)){
       [params setObject:orderCode forKey:@"orderCode"];
    }
    if(!ISBLANK(prodIds)){
        [params setObject:prodIds forKey:@"prodIds"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@cart/accountCenter",BASE_URL] param:params hasT:YES resultClass:[YSAccountCenterRes class] success:success failure:failure];
}

+(void)addOrderWithAddressId:(NSInteger)addressId payMode:(NSInteger)payMode orderCode:(NSString *)orderCode userRemark:(NSString *)userRemark volumePhone:(NSString *)valumePhone voucherId:(NSInteger)voucherId success:(void (^)(YSAddOrderRes *))success failure:(void (^)(NSError *))failure{
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
     [params setObject:[NSNumber numberWithInteger:addressId] forKey:@"addressId"];
     [params setObject:[NSNumber numberWithInteger:payMode] forKey:@"payMode"];
    if(!ISBLANK(orderCode)){
        [params setObject:orderCode forKey:@"orderCode"];
    }
    if(!ISBLANK(userRemark)){
        [params setObject:userRemark forKey:@"userRemark"];
    }
    if(!ISBLANK(valumePhone)){
        [params setObject:valumePhone forKey:@"volumePhone"];
    }
    if(voucherId){
        [params setObject:[NSNumber numberWithInteger:voucherId] forKey:@"voucherId"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@order/add",BASE_URL] param:params hasT:YES resultClass:[YSAddOrderRes class] success:success failure:failure];
}

+(void)getProductComment:(NSInteger)prodId lastCommentId:(NSInteger)lastCommentId success:(void (^)(YSProductDetailRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:prodId] forKey:@"prodId"];
    [params setObject:[NSNumber numberWithInteger:lastCommentId] forKey:@"lastComtId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/comment",BASE_URL] param:params hasT:NO resultClass:[YSProductDetailRes class] success:success failure:failure];
}

+(void)recommentProductWithOrderCode:(NSString *)orderCode commentContent:(NSString *)commentContent success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:orderCode forKey:@"orderCode"];
    [params setObject:commentContent forKey:@"commentContent"];
    [self postWithUrl:[NSString stringWithFormat:@"%@product/recomment",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)getMessageListWithPageIndex:(NSInteger)pageIndex success:(void (^)(YSCommentMsgRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:pageIndex] forKey:@"pageIndex"];
    [self postWithUrl:[NSString stringWithFormat:@"%@interest/replayMessage",BASE_URL] param:params hasT:YES resultClass:[YSCommentMsgRes class] success:success failure:failure];
}

+ (void)getTopicListWithGroupId:(NSInteger)groupId pageIndex:(NSInteger)pageIndex lastId:(NSInteger)lastId success:(void (^)(YSTopicListRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:groupId] forKey:@"groupId"];
    [params setObject:[NSNumber numberWithInteger:pageIndex] forKey:@"pageIndex"];
    [params setObject:[NSNumber numberWithInteger:lastId] forKey:@"lastId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@app/contentsPools",BASE_URL] param:params hasT:NO resultClass:[YSTopicListRes class] success:success failure:failure];
}

+ (void)getGroupDetailWithGroupId:(NSInteger)groupId success:(void (^)(YSGroupDetail *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:groupId] forKey:@"groupId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@interest/groupDetail",BASE_URL] param:params hasT:NO resultClass:[YSGroupDetail class] success:success failure:failure];
}

+ (void)attentionWithGroupId:(NSInteger)groupId type:(NSInteger)type success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:groupId] forKey:@"groupId"];
    [params setObject:[NSNumber numberWithInteger:type] forKey:@"type"];
    [self postWithUrl:[NSString stringWithFormat:@"%@interest/attention",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)praiseWithReviewsId:(NSInteger)reviewsId type:(NSInteger)type success:(void (^)(BaseResponse *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[[BaseRequest param] keyValues]];
    [params setObject:[NSNumber numberWithInteger:reviewsId] forKey:@"reviewsId"];
    [params setObject:[NSNumber numberWithInteger:type] forKey:@"type"];
    [self postWithUrl:[NSString stringWithFormat:@"%@club/praise",BASE_URL] param:params hasT:YES resultClass:[BaseResponse class] success:success failure:failure];
}

@end
